package com.cloudcc.mobile.view.base;

import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;

import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.view.login.LoginNewActivity;
import com.cloudcc.mobile.view.wel.WelcomeActivity;
import com.umeng.message.PushAgent;

import butterknife.ButterKnife;

import static anet.channel.util.Utils.context;

public abstract class BaseActivity extends CommonActivity implements
		OnCancelListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(getLayoutId());
		ButterKnife.bind(this);
		PushAgent.getInstance(context).onAppStart();
		init(savedInstanceState);

	}

	public int getLayoutId() {
		return 0;
	}

	public void init(Bundle savedInstanceState) {

	}

	@Override
	protected void onStart() {
		if(RunTimeManager.getInstance().getServerBinding() == null || RunTimeManager.getInstance().getServerBinding().length() == 0){
			if(RunTimeManager.getInstance().getGoHome()){
				Intent intent = new Intent("android.intent.action.SINGLE_INSTANCE_SHARE");
				intent.setClass(this,WelcomeActivity.class);
				startActivity(intent);
				finish();
			}
		}
		super.onStart();
	}

	//android 开发禁止系统修改app的字体大小

	//重写activity的getResources方法，一般在BaseActivity中重写就好了，其他activity继承BaseActivity
	//设置字体大小不随手机设置而改变
	@Override
	public Resources getResources() {
	Resources res = super.getResources(); 
	Configuration config=new Configuration(); 
	config.setToDefaults(); 
	res.updateConfiguration(config,res.getDisplayMetrics() ); 
	return res; 

	}
}
